import axios from "axios"
import {Toast} from "vant"

export const BASE_RUL = 'http://localhost:88/api'

const request = axios.create({
    baseURL: BASE_RUL,
    timeout: 5000,
    headers: {
        "Token": localStorage.getItem("uid")
    }
})

request.interceptors.response.use(
    //正常响应
    response => {
        //const res = response.data
        //if (!res.status) Toast.fail(res.message)
        console.log("返回的response为：")
        console.log(response);
        
        if(response.status==400 ||(response.data.code && response.data.code==400)) {
            Toast.fail(response.data.message)
        }
        return response
    },

    //响应错误
    error => {
        //return Promise.reject(error);
        Toast.fail("请求错误！")
    }
)

export default request